package hongcaosp.app.android.contact.friends;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import java.util.List;

import hongcaosp.app.android.R;
import hongcaosp.app.android.common.BaseAdapter;
import hongcaosp.app.android.common.BaseHolder;
import hongcaosp.app.android.common.IListView;
import hongcaosp.app.android.contact.ContactHolder;
import hongcaosp.app.android.contact.IMActivity;
import hongcaosp.app.android.login.UserToken;
import hongcaosp.app.android.modle.bean.IUser;
import hongcaosp.app.android.modle.bean.IVideo;
import xlj.lib.android.base.component.BaseActivity;
import xlj.lib.android.base.utils.StatusBarUtil;

public class MyFriendsActivity extends BaseActivity implements IListView<IUser>, OnFriendClickListener {
    private RecyclerView recyclerView;
    private BaseAdapter<IUser> adapter;
    private MyFriendsPresenter myFriendsPresenter;

    @Override
    protected void initData(Intent intent) {

    }

    @Override
    protected void initView() {
        StatusBarUtil.setStatusBarDarkTheme(this, false);
        recyclerView = findViewById(R.id.recycler_view);
        findViewById(R.id.back_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        adapter = new BaseAdapter<IUser>() {
            @NonNull
            @Override
            public BaseHolder<IUser> onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                return new ContactHolder(MyFriendsActivity.this, LayoutInflater.from(MyFriendsActivity.this).inflate(R.layout.item_contact, parent, false),
                        MyFriendsActivity.this);
            }
        };
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayout.VERTICAL, false));
        recyclerView.setAdapter(adapter);
        myFriendsPresenter = new MyFriendsPresenter(this);
        myFriendsPresenter.fresh();
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_myfriend;
    }

    @Override
    public void freshList(List<IUser> data, boolean canLoadMore) {
        adapter.setData(data);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void addList(List<IUser> data, boolean canLoadMore) {

    }

    @Override
    public void onMessageClick(IUser user) {
        if (UserToken.getDefault().isLogged(this)) {
            IMActivity.toIM(this, user.getUserName(), UserToken.getDefault().getUser().getUserId() + "", user.getUserId() + "");
        }
    }

    @Override
    public void onItemClick(IUser user) {

    }

    public static void toActivity(Context context) {
        if (context != null) {
            Intent intent = new Intent(context, MyFriendsActivity.class);
            context.startActivity(intent);
        }
    }
}
